<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('IC会申请') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('投资主体')" prop="fundName">
        <el-input
          v-model="queryParams.fundName"
          :placeholder="$t('投资主体')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('事项类型')" prop="itemType">
        <dict-select
          v-model="queryParams.itemType"
          :placeholder="$t('事项类型')"
          dictionary="ic_item_type"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:icMeeting:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          v-hasPermi="['deal:icMeeting:export']"-->
      <!--          type="warning"-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="exportHandle"-->
      <!--        >{{ $t('导出') }}</el-button>-->
      <!--      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="dealIcMeetingList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请标题')" align="center" prop="actTitle" />
      <el-table-column :label="$t('事项类型')" :formatter="itemTypeFormat" align="center" prop="itemType" />
      <el-table-column :label="$t('投资主体')" align="center" prop="investName" />
      <el-table-column :label="$t('审批状态')" align="center" prop="actStatus">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <ListBtn :bus-data="scope.row" has-permi="deal:icMeeting" />
          <el-button v-if="scope.row.meetingStatus === '0' && !scope.row.commentStatus" type="text" @click="updateComment(scope.row)">{{ $t('结论') }}</el-button>
          <el-button
            v-if="(scope.row.commentStatus === 'N' || !scope.row.commentStatus) && scope.row.actStatus === 'W' && scope.row.meetingStatus === '0'"
            type="text"
            @click="updateVoteHandle(scope.row)"
          >{{ $t(scope.row.voteStatus === 'D' ? '投票中' : (scope.row.voteStatus === 'W' ? '重新投票' : '发起投票')) }}</el-button>
          <el-button v-if="scope.row.meetingStatus === '0'" type="text" @click="getDetail(scope.row)">{{ $t('详情') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目-IC会对话框 -->
    <el-dialog v-if="formOpen" :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealIcMeetingForm ref="dealIcMeetingForm" />
    </el-dialog>

    <el-dialog v-if="meetingOpen" :title="$t(title)" :visible.sync="meetingOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <meeting-detail ref="meetingDetail" />
    </el-dialog>

    <el-dialog v-if="meetingCommentOpen" :title="$t(title)" :visible.sync="meetingCommentOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <mt-conclusion-form ref="mtConclusionForm" />
    </el-dialog>

    <!-- 发起投票对话框 -->
    <el-dialog :title="$t('投票信息')" :visible.sync="voteFormOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <mtVoteForm ref="mtVoteForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listDealIcMeeting, delDealIcMeeting, exportDealIcMeeting } from '@/api/deal/icMeeting/dealIcMeeting'
import dealIcMeetingForm from './dealIcMeetingForm.vue'
import meetingDetail from '@/views/deal/mt/indexForm.vue'
import MtConclusionForm from '@/views/deal/mt/conclusion/mtConclusionForm.vue'
import MtVoteForm from '@/views/deal/mt/vote/mtVoteForm.vue'
export default {
    components: {
      MtVoteForm,
        dealIcMeetingForm,
      meetingDetail,
      MtConclusionForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 项目-IC会表格数据
          dealIcMeetingList: [],
          // 弹出层标题
          title: 'IC会申请',
          // 是否显示弹出层
          formOpen: false,
        meetingOpen: false,
        voteFormOpen: false,
        meetingCommentOpen: false,
          // 查询参数
          queryParams: {
              dealId: this.$route.query.id,
              fundName: undefined,
              itemType: undefined,
              investId: undefined,
              actTitle: undefined,
              applyContent: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {},
        itemTypeOptions: []
      }
  },
  created() {
      this.getDicts('ic_item_type').then(res => {
        this.itemTypeOptions = res.data
      })
      this.getList()
  },
  methods: {
    /** 查询项目-IC会列表 */
    getList() {
        this.loading = true
        listDealIcMeeting(this.queryParams).then(response => {
            this.dealIcMeetingList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },

    itemTypeFormat(row) {
      return this.selectDictLabel(this.itemTypeOptions, row.itemType)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            dealId: undefined,
            itemType: undefined,
            investId: undefined,
            actTitle: undefined,
            applyContent: undefined,
            remark: undefined,
            delFlag: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.dealIcMeetingForm.init(null)
        })
    },
    // 发起投票
    updateVoteHandle(row) {
      var obj = {
        id: row.meetingId,
        showBtn: true,
        process: row.voteStatus !== 'D',
        type: 'ic'
      }
      this.voteFormOpen = true
      this.$nextTick(() => {
        this.$refs.mtVoteForm.init(obj)
      })
    },
    getDetail(row) {
      var obj = {
        id: row.meetingId,
        meetingId: row.meetingId,
        otherBtn: false,
        isCard: true,
        type: 'ic'
      }
      this.meetingOpen = true
      this.$nextTick(() => {
        this.$refs.meetingDetail.init(obj)
      })
    },
    updateComment(row) {
      var obj = {
        meetingId: row.meetingId,
        otherBtn: false,
        isCard: true
      }
      this.meetingCommentOpen = true
      this.$nextTick(() => {
        this.$refs.mtConclusionForm.init(obj)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealIcMeetingForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delDealIcMeeting(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
            this.loading = false
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return exportDealIcMeeting(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(() => {
        })
    }
  }
}
</script>
